set more off
graph drop _all

use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000
	
	by year postcode , sort: egen meangreen = mean(price_green)
	by year postcode , sort: egen meannongreen = mean(price_nongreen)
	
	
	gen greenpremiumyear = meangreen  -  meannongreen
		
	label variable 	roofrelativeIV "Relative Roof Instrument"
	label variable greenpremiumyear "Green Power Premium"
		
	xi: xtivreg2 greenpremiumyear  roofrelativeIV i.year  [aweight=NCustomer], fe  cluster(postcode)

		
	
	
	quietly summ greenpremiumyear [aweight =NCustomer	] if e(sample)
    local meandepvar=round(`r(mean)',.001)

	outreg2 using Analysis/GreenIV.tex, bdec(5) sdec(5) label    ///
	keep(roof* ) addtext(Postcode FE, Yes, Year FE, Yes, Mean dep var, 0`meandepvar') ///
	tex(fragment pretty) nonotes replace
 

 
 
